package com.project.easy.common.util.exception;

import com.project.easy.common.util.constants.CommonConstant;
import com.project.easy.common.util.evn.YqkjZysoftEnvironment;

/**
 * @ClassName BaseException
 * @Description
 * @Author GreatorMan.cool
 * @Date 2020/2/19 14:01
 * @Version 1.0
 **/
public abstract class BaseException extends  RuntimeException {
    /**
     * 系统编码
     */
    protected String sysCode = "base";
    /**
     * 错误编码
     */
    protected String errorCode;
    /**
     * 错误信息
     */
    protected String errorMsg;
    /**
     * 子错误编码
     */
    private String subCode;
    /**
     * 子消息消息
     */
    protected String subMsg;

    /**
     * Constructs a new runtime exception with {@code null} as its
     * detail message.  The cause is not initialized, and may subsequently be
     * initialized by a call to {@link #initCause}.
     */
    public BaseException() {
    }

    /**
     * Constructs a new runtime exception with the specified cause and a
     * detail message of <tt>(cause==null ? null : cause.toString())</tt>
     * (which typically contains the class and detail message of
     * <tt>cause</tt>).  This constructor is useful for runtime exceptions
     * that are little more than wrappers for other throwables.
     *
     * @param cause the cause (which is saved for later retrieval by the
     *              {@link #getCause()} method).  (A <tt>null</tt> value is
     *              permitted, and indicates that the cause is nonexistent or
     *              unknown.)
     * @since 1.4
     */
    public BaseException(Throwable cause) {
        super(cause);
    }
    /**
     * Constructs a new runtime exception with the specified cause and a
     * detail message of <tt>(cause==null ? null : cause.toString())</tt>
     * (which typically contains the class and detail message of
     * <tt>cause</tt>).  This constructor is useful for runtime exceptions
     * that are little more than wrappers for other throwables.
     *
     * @param cause the cause (which is saved for later retrieval by the
     *              {@link #getCause()} method).  (A <tt>null</tt> value is
     *              permitted, and indicates that the cause is nonexistent or
     *              unknown.)
     * @since 1.4
     */
    public BaseException(Throwable cause, String errorCode, String errorMsg, String subCode, String subMsg) {
        super(cause);
        this.sysCode = YqkjZysoftEnvironment.getStr(CommonConstant.YQKJ_SYS_CODE);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.subCode = subCode;
        this.subMsg = subMsg;
    }
    public BaseException(String errorCode, String errorMsg, String subCode, String subMsg) {
        this.sysCode = YqkjZysoftEnvironment.getStr(CommonConstant.YQKJ_SYS_CODE);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.subCode = subCode;
        this.subMsg = subMsg;
    }
    public String getSubCode() {
        return subCode;
    }

    public void setSubCode(String subCode) {
        this.subCode = subCode;
    }

    public String getSubMsg() {
        return subMsg;
    }

    public void setSubMsg(String subMsg) {
        this.subMsg = subMsg;
    }

    public String getSysCode() {
        return sysCode;
    }

    public void setSysCode(String sysCode) {
        this.sysCode = sysCode;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    @Override
    public String toString() {
        return "BaseException{" +
                "sysCode='" + sysCode + '\'' +
                ", errorCode='" + errorCode + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", subCode='" + subCode + '\'' +
                ", subMsg='" + subMsg + '\'' +
                '}';
    }
}
